package com.example.swagger.homework.controller;


import com.example.swagger.homework.common.Result;
import com.example.swagger.homework.domain.Student;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

@RestController
@RequestMapping("student")
@Slf4j
@Api(tags = "学生管理")
public class StudentController {


    @GetMapping("findAll")
    @ApiOperation(value = "查询所有学生",notes = "注释说明性的文字")
    public List<Student> findAll(){
        List<Student> students = new ArrayList<>();
        students.add(new Student("1001","徐坤"));
        students.add(new Student("1002","鸡太美"));
        return students;
    }

    @GetMapping("findByid/{id}")
    @ApiOperation(value = "根据id查询学生",notes = "注释")
    public Student findByid(@PathVariable String id){
        return new Student("1002","鸡太美");
    }

    @PostMapping("add")
    @ApiOperation(value = "添加学生",notes = "注释")
    public Result<String> add(@RequestBody Student student){
        return Result.success("新增学生成功！");
    }

    @PutMapping("updataByid")
    @ApiOperation(value = "根据id修改学生信息",notes = "注释")
    public Result<String> updataByid(@RequestBody Student student){
        return Result.success("修改学生成功！");
    }

    @DeleteMapping("deleteByid/{id}")
    @ApiOperation(value = "根据id删除学生",notes = "注释")
    public Result deleteByid(@PathVariable String id){
        return Result.success("删除id为"+id+"成功！");
    }
}
